<?php

include( "./admin/include/func.php");

if (User::is_logged_in()) header ('Location: index.php');

$db = new db();
if ( ! $db->connect()) exit( mysql_error());

$panels = array ();

$panel = array (
	'caption' => 'Elfelejtett jelszó',
	'title'   => 'Elfelejtett jelszó',
	'body'    => '',
	'height'  => '80'
);

array_push( $panels, $panel);

if (isset($_POST['kuldes'])) {
	
    $p_email = trim(strip_tags($_POST['email']));
       
    $success = true;
    $errors = array();
   
    if (($p_email) != '' && !preg_match('/^[\.\+_a-z0-9-]+@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2}[mtgvu]?$/i', $p_email)) {
        $success = false;
        array_push($errors, "Hibás Email!");
    }
    
    if ($p_email == '') {
        $success = false;
        array_push($errors, "Az Email nincs megadva!");
    }

    if ($success) {		    
		$db->sql = "SELECT bejnev,jelszo FROM users WHERE email='$p_email' LIMIT 1";
		$db->query();
		if (mysql_num_rows( $db->rs) < 1) {
			$success = false;
			array_push( $errors, "Ezzel az email cimmel még nem regisztráltak!");
		}
	}
		
	if ($success) {
		
		$d_user = mysql_fetch_assoc( $db->rs);
		
		// jelszo emlekezteto email kuldese 
		$message = "

Tisztelt " . ucfirst( $d_user['bejnev']) . "! 
     
A bejelentkezéshez használhatja az email címét vagy 
a felhasználónevét amely: " . $d_user['bejnev'] . "
valamint a következő jelszót: " . $d_user['jelszo'] . "

Üdvözlettel: a $url csapata";  

		mail ($p_email, "Jelszo emlekezteto", $message, "From: ".$noreply); 
		
		//print $message;

		$panels = array ();

		$panel = array (
			'caption' => 'Információ',
			'title'   => 'Jelszó emlékeztető elküldve!',
			'body'    => "<p class='success'>A bejelentkezéshez szükséges adatait elküldtük az email címére.</p>",
			'height'  => '20'
		);
		
		array_push( $panels, $panel);
		
    } else {
		
		$body    = "<ul class='errors'>";
		foreach ($errors as $err) $body .= "<li>$err</li>";
		$body   .= "</ul>";
		
		$error_panel = array (
			'caption' => 'Hiba',
			'title'   => 'Kérjük javítsa ki az alábbi hibákat!',
			'body'    => $body,
			'height'  => count( $errors) * 25 + 10
		);
		
		array_unshift( $panels, $error_panel);
	}
}

?>

<?php include ("header.php"); ?>

<?php include ("top.php"); ?>

<?php include ("left.php"); ?>
							
<div id="middle">

<?php foreach( $panels as $panel) { ?>
	
	<div class="form-panel">		
		<div>
			<img src='./images1/x3a2.gif' width="21px" height="42px" class="fleft" alt='apróhirdetés' /> 
			<div class="hptop">
				<p class="hpcaption"><?php print $panel['caption']; ?></p>
				<p class="hptitle"><?php print $panel['title']; ?></p>
			</div>	
			<img src='./images1/x3b2.gif' width="21px" height="42px" class="fleft" alt='apróhirdetés' />
		</div>
		<div>
			<img src='./images1/x4a.gif' width="21px" height="13px" class="fleft" alt='apróhirdetés' /> 
			<img src='./images1/x4bg.gif' width="455px" height="13px" class="fleft" alt='apróhirdetés' /> 
			<img src='./images1/x4b.gif' width="21px" height="13px" class="fleft" alt='apróhirdetés' />
		</div>
		<div>
			<img src='./images1/x5bga.gif' width="21px" height="<?php print $panel['height']; ?>px" class="fleft" alt='apróhirdetés' /> 
			<div class="hpbody" style="height:<?php print $panel['height']; ?>px">
				<?php if ($panel['body'] != '') print $panel['body']; else { ?>
					<form name="form_hirdetes" id="form_hirdetes" method="post" enctype='multipart/form-data' accept-charset="utf-8">										
						
						<label for='email' class="required">Email cím</label>
						<input name='email' type='text' <?php if (isset($p_email) && !$success) print "value='$p_email'"; ?> />
						<br />
						
						<br />	
															
						<label for="kuldes">&nbsp;</label>
						<input name="kuldes" type="submit" value="Jelszó küldése"/>						

					</form> 
				<?php } ?>           			
			</div>
			<img src='./images1/x5bgb.gif' width="21px" height="<?php print $panel['height']; ?>px" class="fleft" alt='apróhirdetés' />
		</div>
		<div>
			<img src='./images1/x6a.gif' width="21px" height="34px" class="fleft" alt='apróhirdetés' /> 
			<img src='./images1/x6bg.gif' width="455px" height="34px" class="fleft" alt='apróhirdetés' /> 		
			<img src='./images1/x6b.gif' width="21px" height="34px" class="fleft" alt='apróhirdetés' />
		</div>
	</div>

	<br />
	<br />

<?php } ?>

<br />

</div>

<?php include ("right.php"); ?>

<?php include ("footer.php"); ?>
